<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        // var arr = [1, 2, 3, 4, 3, 2, 1];
        var arr = [1,100,50,-51,1,1];
        var total = 0;
        var left = 0;
        var right = 0;
        for (var i = 0; i <= arr.length - 1; i++) {
            total = total + arr[i];
        }
        for (var i = 1; i <= arr.length - 1; i++) {
                left = left + arr[i-1];
                right = total - left - arr[i];
                if(right == left){
                    var num = i;
                }
            }
        console.log(num);

        // var arr = [1,100,50,-51,1,1];
        // // var arr = [1, 2, 3, 4, 3, 2, 1];
        // var left = 0;
        // var right = 0;
        // for(var i = 1; i<arr.length-1;i++){
        //     var result1 = arr.slice(0,i);
        //     var result2 = arr.slice(i+1);
        //     for(var j = 0;j<=result1.length-1;j++){
        //         left = left + result1[j];
        //     }
        //     for(var b = 0;b<=result2.length-1;b++){
        //         right = right + result2[b];
        //         if(left == right){
        //             var num = i;
        //         }
        //     }
        // }
        // console.log(num);



    </script>



</body>

</html>